from django.shortcuts import render, HttpResponseRedirect
from django.contrib import auth


# Create your views here.
def login(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(username=username, password=password)
        if user:
            auth.login(request, user)
            return HttpResponseRedirect('index')
    else:
        return render(request, 'user/index.html')
    return HttpResponseRedirect('crm/index')
